const CryptoJS = require("crypto-js");
const privateKey = 'sps@pc!22'

// 加密生成密文
function encrypt(obj) {
  return CryptoJS.AES.encrypt(obj, privateKey).toString();
}

// 解密
function decrypt(txt) {
  if (txt.indexOf(' ') !== -1) {
    txt = txt.replaceAll(' ', '+')
  }
  const bytes = CryptoJS.AES.decrypt(txt, privateKey);
  const decryptedData = JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
  return decryptedData
}

export {
  decrypt, encrypt
}

